package com.project.internship.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.internship.entity.Position;
import com.project.internship.mapper.PositionMapper;
import com.project.internship.service.PositionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.internship.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2020-04-11
 */
@Service
public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> implements PositionService {

    @Autowired
    PositionMapper positionMapper;

    @Override
    public List<Position> getTheBasePosition() {
        return positionMapper.getTheBasePosition(UserUtils.getCurrentUser().getBaseId());
    }

    @Override
    public Integer addPosition(Position position) {
        position.setBid(UserUtils.getCurrentUser().getBaseId());
        return positionMapper.insert(position);
    }

    @Override
    public Integer deletePosition(Position position) {
        QueryWrapper<Position> wrapper = new QueryWrapper<>();
        wrapper.select("id")
                .eq("bid", UserUtils.getCurrentUser().getBaseId())
                .like("name",position.getName());
        Position p = positionMapper.selectOne(wrapper);
        return positionMapper.deleteById(p.getId());
    }

}
